package com.gxa.insurance.controller;

import com.gxa.insurance.exception.BusinessException;
import com.gxa.insurance.exception.ExceptionCode;
import com.gxa.insurance.pojo.Driver;
import com.gxa.insurance.pojo.RepairDepot;
import com.gxa.insurance.pojo.S4Shop;
import com.gxa.insurance.service.AreaService;
import com.gxa.insurance.util.JsonResult;
import com.gxa.insurance.util.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author wang li sha
 * @date 2022-06-06 17:58
 */
@Api(value = "地区area相关的api接口")
@RestController
@RequestMapping("/area")
@CrossOrigin
public class AreaController {
    @Autowired
    AreaService areaService;


    @ApiOperation("查询所有区域的方法")
    @PostMapping("/selectAll")
    public Map selectAll() throws Exception {
        List<String> areas = areaService.selectAll();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(areas);
        return jsonResult.getMap();
    }

    @ApiOperation("联动查询此区域的4s店")
    @GetMapping("/selectFourS")
    public Map selectFourS(@RequestParam("areaName")String areaName) throws BusinessException {
        if(StringUtil.isEmpty(areaName)){
            throw new BusinessException(ExceptionCode.WRONG_VALUE);
        }
        List<List<S4Shop>>  fourS= areaService.selectFourS(areaName);
        JsonResult jsonResult = new JsonResult();
        if(fourS.size()<=0){
            jsonResult.setCode("0");
            jsonResult.setMsg("列表为空");
        }else {
            jsonResult.setCode("1");
            jsonResult.setMsg("查询成功");
            jsonResult.setData(fourS);
        }
        return jsonResult.getMap();
    }

    @ApiOperation("联动区域查询此区域的修理厂")
    @GetMapping("/selectRepairF")
    public Map selectRepairF(@RequestParam("areaName")String areaName) throws BusinessException {
        if(StringUtil.isEmpty(areaName)){
            throw new BusinessException(ExceptionCode.WRONG_VALUE);
        }
        List<List<RepairDepot>> repairFs= areaService.selectRepairFs(areaName);
        JsonResult jsonResult = new JsonResult();
        if(repairFs.size()<=0){
            jsonResult.setCode("0");
            jsonResult.setMsg("列表为空");
        }else {
            jsonResult.setCode("1");
            jsonResult.setMsg("查询成功");
            jsonResult.setData(repairFs);
        }
        return jsonResult.getMap();
    }

    @ApiOperation("联动区域查询司机")
    @GetMapping("/selectDriver")
    public Map selectDriver(@RequestParam("areaName")String areaName)throws BusinessException{
        if(StringUtil.isEmpty(areaName)){
            throw new BusinessException(ExceptionCode.WRONG_VALUE);
        }
        List<List<Driver>>  drivers= areaService.selectDrivers(areaName);
        JsonResult jsonResult = new JsonResult();
        if(drivers.size()<=0){
            jsonResult.setCode("0");
            jsonResult.setMsg("列表为空");
        }else {
            jsonResult.setCode("1");
            jsonResult.setMsg("查询成功");
            jsonResult.setData(drivers);
        }
        return jsonResult.getMap();
    }
}
